properties {
  $projectName = "Unbound"
  $base_dir = resolve-path .
  $build_dir = "$base_dir\build"
  $source_dir = "$base_dir\source"
  $test_dir = "$base_dir\test"
  $test_asm = "$test_dir\Unbound.Tests.dll" 
  $test_run = "$base_dir\lib\mspec\mspec.exe" 
}

task default -depends Test, Compile

task CompileForTest -depends Clean { 
    create_directory $test_dir		
    msbuild /t:build /verbosity:m /nologo /property:"Configuration=Debug" /p:OutDir="$test_dir"\\ $source_dir\Unbound.sln
}

task Compile -depends Clean {
    create_directory $build_dir
    msbuild /t:build /verbosity:m /nologo /property:"Configuration=Release" /p:OutDir="$build_dir"\\ $source_dir\Unbound.sln	
}

task Clean { 
    delete_directory $build_dir
    delete_directory $test_dir
    msbuild /t:clean /nologo /verbosity:m $source_dir\$projectName.sln 
}

task Test -depends CompileForTest {
    exec { 
		& $test_run $test_asm 
		delete_directory $test_dir
    } "Build failed - test failure"
    
}

function global:delete_directory($directory_name)
{
  rd $directory_name -recurse -force  -ErrorAction SilentlyContinue | out-null
}

function global:create_directory($directory_name)
{
  mkdir $directory_name  -ErrorAction SilentlyContinue  | out-null
}

function global:copy_files($source,$destination,$exclude=@()){    
    create_directory $destination
    Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)} 
}